function R = kneu_train_smlr(TRAIN,LABEL,param)
% Trains sparse multinomial logistic regression (SMLR) to predict your regressors
%
% [alg] = TRAIN_SMLR(TRAINPATS,TRAINTARGS,IN_ARGS,CV_ARGS)
%
% Trains a Sparse Multinomial Logistic Regression (SMLR) algorithm
% to predict regressors of interest. For details on the algorithm
% and optional arguemnts, see SMLR.m. 
%
% Arguments:
% 
%   TRAINPATS - A  N x D input matrix of training patterns.
% 
%   TRAINTARGS - A N x M matrix of training labels using one-of-M encoding.

% Outputs:
%
%   SCRATCHPAD - The structure containing all the output of the
%    SMLR algorithm.
%
% SEE ALSO SMLR, TEST_SMLR           

% License:
%=====================================================================
%
% This is part of the Princeton MVPA toolbox, released under
% the GPL. See http://www.csbmb.princeton.edu/mvpa for more
% information.
% 
% The Princeton MVPA toolbox is available free and
% unsupported to those who might find it useful. We do not
% take any responsibility whatsoever for any problems that
% you have related to the use of the MVPA toolbox.
%
% ======================================================================
% modified by CR, Dept. of Neurology, Magdeburg


R.classes = unique(LABEL);
nclasses=length(R.classes);
LABELmat = zeros(length(LABEL),nclasses);
for c_i = 1:nclasses,
    LABELmat(LABEL==R.classes(c_i),c_i) = 1;
end

% Run SMLR with whatever options the user has passed in
[R.w R.class_args] = kneu_smlr(TRAIN, LABELmat, 'param', param);